﻿@using Newtouch.Infrastructure;
@model dynamic

@{
    ViewBag.Title = "审核明细";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script type="text/javascript" src="~/Content/js/jquery.formatCurrency.js"></script>
<script type="text/javascript">
    var keyValue = $.request("keyValue");
    var from = $.request("from");
    $(function () {
        if (!!keyValue) {
            $.najax({
                url: "/SiteManage/SiteStatistics/GetFormJson?keyWord=" + keyValue,
                dataType: "json",
                type: "POST",
                success: function (data) {
                    var rtndata = JSON.parse(data.message);
                    $("#form1").formSerialize(rtndata.srxx);
                    //收入信息
                    initsrxxtable(rtndata.srxxList, rtndata.srxx.siteId);
                    //成本详情
                    initcbxxtable(rtndata.cbxxList);
                    $('#jgss').html(rtndata.srxx.jgss).formatCurrency();
                    $('#grsss').html(rtndata.srxx.grsss).formatCurrency();
                    $('#year').html(rtndata.srxx.year);
                    $('#month').html(rtndata.srxx.month);
                    $('#zdmc').html(rtndata.srxx.zdmc);
                    $('#cjr').html(rtndata.srxx.cjr);
                    $('#shr').html(rtndata.srxx.shr);
                    //附件信息
                    var fjhtml = "";
                    if (rtndata.fjxx != null && rtndata.fjxx.length > 0)
                    {
                        for (var i = 0; i < rtndata.fjxx.length; i++) {
                            fjhtml += "<a id='file" + i + "' href='/SiteManage/SiteStatistics/download?id=" + rtndata.fjxx[i].Id+"'>" + rtndata.fjxx[i].fjmc + "</a><br/>";
                            $('file' + i).attr("href", "/SiteManage/SiteStatistics/download?id=" + rtndata.fjxx[i].Id);
                        }

                    }
                    $('#fjcontent').html(fjhtml);
                    $('.money').formatCurrency();
                    //$('#fjcontent').attr("href", "/SiteManage/SiteStatistics/download?id=" + keyValue);
                    $('#btn_cxsh').attr("style", "display:none");
                    if (rtndata.srxx.shzt == '@Html.Raw(((int)EnumOrgshzt.DS).ToString())' && from !== "index") {
                        $('#shr').html('@ViewBag.currentUserName');
                    }
                    if (rtndata.srxx.shzt !== '@Html.Raw(((int)EnumOrgshzt.DS).ToString())' || from=="index") {
                        $('#btn_shtg').attr("style", "display:none");
                        $('#btn_shbtg').attr("style", "display:none");
                    }
                    if (rtndata.srxx.shzt=='@Html.Raw(((int)EnumOrgshzt.TG).ToString())'&&from!="index") {
                        $('#btn_cxsh').attr("style", "float: right;margin-right:10px;");
                    }
                }
            });
        }
    });

    function initsrxxtable(srxxList, siteId) {
        var html = "";
        var zsr = 0.00;
        var zhssr = 0.00;
        var zce = 0.00;
        var fczsr = 0.00;
        $.each(srxxList, function () {
            zce += this.ce;
            zhssr += this.hssr;
            zsr += this.zsr;
            fczsr += this.hssr * this.fcbl / 100;
            html += "<tr><td class='title-content'>" + this.dlmc + "</td>";
            html += "<td class='money' style='text-decoration:underline;cursor:pointer' onclick=\"btn_detail('" + this.dlCode + "','outpatient','" + siteId + "')\">" + this.mzsfje + "</td > ";
            html += "<td class='money'>" + this.mzzxje + "</td>";
            html += "<td class='money' style='text-decoration:underline;cursor:pointer' onclick=\"btn_detail('" + this.dlCode + "','inpatient','" + siteId + "')\">" + this.zysfje + "</td>";
            html += "<td class='money'>" + this.zyzxje + "</td>";
            html += "<td class='money'>" + this.zsr + "</td>";
            html += "<td class='money'>" + (this.hssr || "0.00") + "</td>";
            html += "<td class='monright'>" + (this.fcbl || "0") + "%</td>";
            html += "<td class='money'>" + (this.ce || "0.00")  + "</td>";
            html += "<td style=\"max-width: 200px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;\"><a title=" + (this.tzsm || "")+">" + (this.tzsm || "") + "</a></td>";
            html += "</tr > ";
        });
        html += "<tr><td class='title-content' colspan='5'>合计(元)</td>";
        html += "<td class='money' > " + zsr + "</td >";
        html += "<td class='money' > " + zhssr + "</td >";
        html += "<td class='money' >" + fczsr + "</td >";
        html += "<td class='money' > " + zce + "</td >";
        html += "<td class='money' ></td >";
        html += "</tr > ";
        $('#srcol').after(html);
    }

    //查看收费金额详情
    function btn_detail(dlcode, type, siteId) {
        $.modalOpen({
            id: "ViewChargeMoneyDetail",
            title: "查看收费详情",
            url: "/SiteManage/SiteStatistics/ViewChargeMoneyDetail?year=" + $('#year').val() + "&siteId=" + siteId + "&month=" + $('#month').val() + "&dlcode=" + dlcode + "&type=" + type,
            width: "1000px",
            height: "580px",
            btn: null
        });
    }

    function initcbxxtable(cbxxList) {
        var gd = [];
        var fd = [];
        for (var i = 0; i < cbxxList.length; i++) {
            var item = cbxxList[i];
            if (item.cblb === 'GRSbillObj') {
                fd.push(item);
            } else {
                gd.push(item);
            }
        }

        var len = fd.length > gd.length ? fd.length : gd.length;
        if (len > 0) {
            var html = " <tr><th class='th2' colspan='10'>支出统计</th></tr>"+
                 "<tr>" +
                "<td rowspan='" + len + 1 + "'>共担成本</td>" +
                "<td colspan='2'>科目类别</td>" +
                "<td colspan='2'>金额(元)</td>" +
                "<td rowspan='" + len + 1 + "'>GRS负担成本</td>" +
                "<td colspan='2'>科目类别</td>" +
                "<td colspan='2'>金额(元)</td>" +
                "</tr > ";

            for (var i = 0; i < len; i++) {
                var gdObj = gd[i] || null;
                var fdObj = fd[i] || null;

                if (gdObj && fdObj) {
                    html += "<tr>" +
                        "<td colspan='2'>" + gdObj.kmmc + "</td>" +
                        "<td class='money' colspan='2'>" + gdObj.je + "</td>" +

                        "<td colspan='2'>" + fdObj.kmmc + "</td>" +
                        "<td class='money' colspan='2'>" + fdObj.je + "</td>" +
                        "</tr>";

                } else if (gdObj && !fdObj) {
                    html += "<tr>" +
                        "<td colspan='2'>" + gdObj.kmmc + "</td>" +
                        "<td class='money' colspan='2'>" + gdObj.je + "</td>" +

                        "<td colspan='2'></td>" +
                        "<td colspan='2'></td>" +
                        "</tr>";
                } else if (!gdObj && fdObj) {
                    html += "<tr>" +
                        "<td colspan='2'></td>" +
                        "<td colspan='2'></td>" +

                        "<td colspan='2'>" + fdObj.kmmc + "</td>" +
                        "<td class='money' colspan='2'>" + fdObj.je + "</td>" +
                        "</tr>";
                }
            }
        }
      
        $('#cbcol').after(html);
    }

    function btnclick(shzt) {
        $.najax({
            url: "/SiteManage/SiteStatistics/updateshzt?id=" + keyValue + "&shzt=" + shzt,
            dataType: "json",
            success: function () {
                $.modalMsg("操作成功", "success");
                $.currentWindow().$('#gridList').jqGrid("clearGridData"); //清除明细的grid
                $.currentWindow().$("#btn_search").trigger("click");
                $.modalClose();
            }
        });
    }

    function cxsh() {
        window.$.modalConfirm("确定要撤销审核吗？", function (flag) {
            if (flag) {
               
                btnclick('@Html.Raw(((int)EnumOrgshzt.WTG).ToString())');
            }
        });
    }
</script>
<style>
    .dv-panel {
        width: 100%;
        /*height: 690px;*/
        overflow-y: auto;
    }

    table {
        margin: 10px;
        border: 1px double #000;
        height: 98%;
        width: 98%;
    }

    .th1 {
        text-align: center;
        font-size: large;
        padding: 5px;
    }

    .th2 {
        text-align: center;
        font-size: medium;
        padding: 5px;
    }

    .sp-content {
        display: block;
        font-size: small;
        font-weight: bold;
    }

    th, td {
        border: 1px solid #000000;
        text-align: center;
        vertical-align: middle;
        width: 110px;
        padding: 3px 10px;
    }

    .title-content {
        font-size: x-small;
        font-weight: bold;
    }
    .money, .monright {
        text-align: right;
    }
</style>
<div class="dv-panel">
    <table align="center" id="form1">
        <tr>
            <th class="th1" colspan="10">站点收支统计</th>
        </tr>
        <tr>
            <td colspan="10" style="text-align: left;">
                <span class="sp-content">统计时间：<label id="year"></label>年<label id="month"></label>月</span>
                <span class="sp-content">所属站点：<label id="zdmc"></label></span>
            </td>
        </tr>
        <tr><th class="th2" colspan="10">收入统计</th></tr>
        <tr>
            <td rowspan="2" class="title-content" style="min-width: 53px;">科室</td>
            <td colspan="2" class="title-content">门诊收入</td>
            <td colspan="2" class="title-content">住院收入</td>
            <td class="title-content" rowspan="2">总收入</td>
            <td class="title-content" rowspan="2">核实收入</td>
            <td class="title-content" rowspan="2">分成比例</td>
            <td class="title-content" rowspan="2">差额</td>
            <td class="title-content" rowspan="2">调整说明</td>
        </tr>
        <tr>

            <td class="title-content">收费金额(元)</td>
            <td class="title-content">执行金额(元)</td>
            <td class="title-content">收费金额(元)</td>
            <td class="title-content">执行金额(元)</td>
        </tr>
        <tbody id="srcol"></tbody>
        <tbody id="cbcol"></tbody>

        <tr>
            <td class="title-content">机构实收(元)</td>
            <td colspan="9" style="text-align: left;">
                <span id="jgss"></span>
                <span style="float:right">
                    (每个收费大类核实收入*(每个收费大类分成比例))之和减(共担成本之和*(1-共担成本分担比例))
                </span>
            </td>
        </tr>
        <tr>
            <td class="title-content">GRS实收(元)</td>
            <td colspan="9" style="text-align: left;">
                <span id="grsss"></span>   <span style="float:right">
    (每个收费大类核实收入*(1-每个收费大类分成比例))之和减(共担成本之和*共担成本分担比例)-GRS成本
</span>
            </td>
        </tr>
        <tr><th class="th2" colspan="11"></th></tr>
        <tr>
            <td class="title-content">制表人</td>
            <td style="text-align: left;"><label id="cjr"></label></td>
            <td class="title-content">审核人</td>
            <td colspan="7" style="text-align: left;"><label id="shr"></label></td>
        </tr>
        <tr>
            <td class="title-content">费用支持文件</td>
            <td colspan="9" style="text-align: left;"><div id="fjcontent"></div></td>
        </tr>

    </table>
</div>
<input type="button" id="btn_shtg" onclick="btnclick('@Html.Raw(((int)EnumOrgshzt.TG).ToString())')" class="btn btn-primary btn-md" value="审核通过" style="float: right;margin-top: 10px;margin-bottom: 10px;margin-right: 10px;" />
<input type="button" id="btn_shbtg" onclick="btnclick('@Html.Raw(((int)EnumOrgshzt.WTG).ToString())')" class="btn btn-primary btn-md" value="审核不通过" style="float: right;margin-top: 10px;margin-bottom: 10px;margin-right: 10px;" />
<input type="button" hidden id="btn_cxsh" onclick="cxsh()" class="btn btn-primary btn-md" value="撤销审核" style="float: right;margin-top: 10px;margin-bottom: 10px;margin-right: 20px;" />